/*
 * Copyright 2013 Agustina Martinez-Garcia

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package uk.ljmu.metadata.staticschemas;

import java.io.InputStream;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.Resource;

public class StaticJenaRDF {
    /** <p>The RDF model that holds the vocabulary terms</p> */
    private static Model m_model = ModelFactory.createDefaultModel();
    
    /** <p>The namespace of the vocabulary as a string</p> */
    public static final String NS = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
    
    /** <p>The namespace of the vocabulary as a string</p>
     *  @see #NS */
    public static String getURI() {return NS;}
    
    /** <p>The namespace of the vocabulary as a resource</p> */
    public static final Resource NAMESPACE = m_model.createResource( NS );
    
    /** <p>The first item in the subject RDF list.</p> */
    public static final Property first = m_model.createProperty( "http://www.w3.org/1999/02/22-rdf-syntax-ns#first" );
    
    /** <p>The object of the subject RDF statement.</p> */
    public static final Property object = m_model.createProperty( "http://www.w3.org/1999/02/22-rdf-syntax-ns#object" );
    
    /** <p>The predicate of the subject RDF statement.</p> */
    public static final Property predicate = m_model.createProperty( "http://www.w3.org/1999/02/22-rdf-syntax-ns#predicate" );
    
    /** <p>The rest of the subject RDF list after the first item.</p> */
    public static final Property rest = m_model.createProperty( "http://www.w3.org/1999/02/22-rdf-syntax-ns#rest" );
    
    /** <p>The subject of the subject RDF statement.</p> */
    public static final Property subject = m_model.createProperty( "http://www.w3.org/1999/02/22-rdf-syntax-ns#subject" );
    
    /** <p>The subject is an instance of a class.</p> */
    public static final Property type = m_model.createProperty( "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" );
    
    /** <p>Idiomatic property used for structured values.</p> */
    public static final Property value = m_model.createProperty( "http://www.w3.org/1999/02/22-rdf-syntax-ns#value" );
    
    /** <p>The empty list, with no items in it. If the rest of a list is nil then the 
     *  list has no more items in it.</p>
     */
    public static final Resource nil = m_model.createResource( "http://www.w3.org/1999/02/22-rdf-syntax-ns#nil" );
    
    public static Model getModel()
    {
	ClassLoader classLoader = Thread.currentThread()
	.getContextClassLoader();
	InputStream is;
	is = classLoader.getResourceAsStream("rdf.rdf");

    	Model myModel = ModelFactory.createDefaultModel();
    	
    	try {
    	    myModel.read(is, "");
    	    return myModel;
    	}catch (Exception ex) {
    	    return myModel;
    	}      
    }
    
    public static boolean containsProperty(String localName)
    {
    	if (StaticJenaRDF.first.getLocalName().equals(localName) ||
    			StaticJenaRDF.object.getLocalName().equals(localName) ||
    			StaticJenaRDF.predicate.getLocalName().equals(localName) ||
    			StaticJenaRDF.subject.getLocalName().equals(localName) ||
    			StaticJenaRDF.type.getLocalName().equals(localName) ||
    			StaticJenaRDF.value.getLocalName().equals(localName))
    		return true;
    	else return false;
    }
    
    public static boolean containsResource(String localName)
    {
    	if (StaticJenaRDF.nil.getLocalName().equals(localName))
    		return true;
    	else return false;
    }
}